package com.Iconcat.system.mapper;

import com.Iconcat.system.entity.DrawRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zzq
 * @since 2023-11-13
 */
@Mapper
public interface DrawRecordMapper extends BaseMapper<DrawRecord> {
//    /**
//     * 根据用户ID查询抽奖次数
//     * @param userId 用户ID
//     * @return 抽奖次数
//     */
//    DrawRecord  selectDrawCountByUserId(@Param("userId") Integer userId);

    List<DrawRecord> selectDrawRecordWithPrize(
            @Param("userId") Integer userId,
            @Param("offset") Integer offset,
            @Param("size") Integer size
    );
    @Select("SELECT " +
            "draw_record.*, " +
            "cat_prize.prize_type,"+
            "cat_prize.prize_name AS prizeName, " +
            "cat_user.userid AS user_userid, " +
            "cat_user.user_name, " +
            "cat_user.phone_number " +
            "FROM draw_record " +
            "LEFT JOIN cat_prize ON draw_record.prize_id = cat_prize.prize_id " +
            "LEFT JOIN cat_user ON draw_record.userid = cat_user.userid " )
    IPage<Map<String, Object>> getDrawRecordListPage(Page<DrawRecord> page);
    @Select("select count(*) from draw_record where userid=#{userid}")
    int selectTotalDrawRecordCount(@Param("userId") Integer userId);
}
